package com.xzq.springframework.beans.factory.config;

import cn.hutool.core.lang.Assert;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author xzq
 * @Description // 单例Bean注册的实现类
 * @Date 2021/11/24 11:26
 * @Version 1.0.0
 **/
public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry{

    /**
     * 一级缓存 ,完成实例化和初始化之后的缓存Bean实例
     */
    private Map<String, Object> singletonObjects = new HashMap<>();

    @Override
    public void registerSingleton(String beanName, Object singletonObject) {
        Assert.notNull(beanName, "Bean name must not be null");
        Assert.notNull(singletonObject, "Singleton object must not be null");
        singletonObjects.put(beanName, singletonObject);
    }

    @Override
    public Object getSinleton(String beanName) {
        return singletonObjects.get(beanName);
    }

}
